package mo.golden;

import java.util.HashMap;
import java.util.Map;

public class L01_02 {

    public boolean CheckPermutation(String s1, String s2) {
        if (s1 == null && s2 == null) {
            return true;
        }
        if (s1 == null || s2 == null) {
            return false;
        }
        if (s1.length() != s2.length()) {
            return false;
        }
        Map<Character, Integer> s1Map = new HashMap<>();
        for (char c : s1.toCharArray()) {
            s1Map.put(c, s1Map.getOrDefault(c, 0)+1);
        }
        Map<Character, Integer> s2Map = new HashMap<>();
        for (char c : s2.toCharArray()) {
            s2Map.put(c, s2Map.getOrDefault(c, 0)+1);
        }
        for (Map.Entry<Character, Integer> entry : s1Map.entrySet()) {
            Integer value1 = entry.getValue();
            Integer value2 = s2Map.get(entry.getKey());
            if (value2 == null || !value2.equals(value1)) {
                return false;
            }
        }
        return true;
    }

}
